Imports System.Data.SqlClient
Imports System.Drawing
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Controls

'--- Created Date On : 12-Oct-2010 (Jagdish)

Public Class frmDaysPatient
    Dim FromDate, ToDate As Date
    Private Sub frmDaysPatient_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Call SetImageControl(Me)
        Call GetAccessPermission(Me, "frmDaysPatient")
        'Call PopulateLookupDX(cboDate, "VisitDate", "ID", "tblVisits group by convert(varchar(3),Month(VisitDate)) + '/' + convert(varchar(3),day(VisitDate)) + '/' + convert(varchar(5),Year(VisitDate)) ", "convert(varchar(3),Month(VisitDate)) + '/' + convert(varchar(3),day(VisitDate)) + '/' + convert(varchar(5),Year(VisitDate)) [ID],max(VisitDate) [VisitDate] ")
        '' ''Dim dsTemp As DataSet = FillDataSet("select convert(varchar(3),Month(VisitDate)) + '/' + convert(varchar(3),day(VisitDate)) + '/' + convert(varchar(5),Year(VisitDate)) [ID],max(VisitDate) [VisitDate] " & _
        '' ''                                    "from tblVisits group by convert(varchar(3),Month(VisitDate)) + '/' + convert(varchar(3),day(VisitDate)) + '/' + convert(varchar(5),Year(VisitDate)) ")
        Dim dstemp As DataSet = FillDataSet("SELECT Distinct CONVERT(VARCHAR(10),VisitDate,111) [Visit Date] " & _
                                            " From tblVisits order by CONVERT(VARCHAR(10),VisitDate,111) desc")
        With cboDate.Properties
            .Columns.Clear()

            .DataSource = dsTemp.Tables(0)
            .DisplayMember = "Visit Date"
            .ValueMember = "Visit Date"

            'Add columns to the dropdown.
            Dim coll As LookUpColumnInfoCollection = .Columns

            coll.Add(New LookUpColumnInfo(dstemp.Tables(0).Columns(0).Caption, 0))


            'Set column widths according to their contents.
            .BestFit()

            'Specify the total dropdown width.
            '.PopupWidth = intPopupWidth

            'Enable auto completion search mode.
            .SearchMode = SearchMode.AutoComplete
            'Specify the column against which to perform the search.
            .AutoSearchColumnIndex = 1

            '.Columns(0).Visible = False 'ID field
            .ShowFooter = False
        End With
        
        rgbSelectDate.SelectedIndex = 0
        grbTodaysDate.Visible = True
        dtTodaysDate.EditValue = Format(Today, gstrDtFormat)
        dteToDate.EditValue = Format(Today, gstrDtFormat)
        dteFromDate.EditValue = Format(Today, gstrDtFormat)
    End Sub

    Private Sub rgbSelectDate_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rgbSelectDate.SelectedIndexChanged
        If rgbSelectDate.SelectedIndex = 0 Then
            grbTodaysDate.Visible = True
            grbSelectDate.Visible = False
            grbSelectDateRange.Visible = False
            dtTodaysDate.EditValue = Format(Today, gstrDtFormat)
        ElseIf rgbSelectDate.SelectedIndex = 1 Then
            grbTodaysDate.Visible = False
            grbSelectDate.Visible = True
            grbSelectDateRange.Visible = False
            cboDate.ItemIndex = 0
        ElseIf rgbSelectDate.SelectedIndex = 2 Then
            grbTodaysDate.Visible = False
            grbSelectDate.Visible = False
            grbSelectDateRange.Visible = True
            dteToDate.EditValue = Format(Today, gstrDtFormat)
            dteFromDate.EditValue = DateAdd(DateInterval.Month, -1, dteToDate.EditValue)
        End If
    End Sub

    Private Sub btnReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReport.Click
        Try

            If rgbSelectDate.SelectedIndex = 0 Then
                FromDate = Format(CDate(dtTodaysDate.EditValue), gstrDtFormat)
                ToDate = Format(CDate(dtTodaysDate.EditValue), gstrDtFormat)
            ElseIf rgbSelectDate.SelectedIndex = 1 Then
                FromDate = Format(CDate(cboDate.EditValue), gstrDtFormat)
                ToDate = Format(CDate(cboDate.EditValue), gstrDtFormat)

            ElseIf rgbSelectDate.SelectedIndex = 2 Then
                FromDate = Format(CDate(dteFromDate.EditValue), gstrDtFormat)
                ToDate = Format(CDate(dteToDate.EditValue), gstrDtFormat)
            End If
            Call ShowDaysPatient(FromDate, ToDate, rgbSelectDate.SelectedIndex, Me.ParentForm)
        Catch ex As Exception
            MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
        End Try

    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub
End Class
